// pages/riskAlarm/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    equList: [],
    option2: [
      { text: '报警日期', value: 'a' },
      { text: '报警日期', value: 'b' },
      { text: '报警日期', value: 'c' },
    ],
    deviceId: '',
    value2: 'a',
    alertList:[],
    tableList: [1, 2, 3, 4, 5]
  },
  onChange(event){
    // 下拉菜单改变时触发
    console.log('当前下拉项的索引：', event.detail);
    console.log(this.data.orderStateValue)
    this.setData({
        deviceId:event.detail
    })
    this.getInfo()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 获取环境设备列表
    wx.$req({
      url: '/wms/monitor/getUserEquipmentsData',
      method: 'post',
      data:{deviceType:'1777600292192288769'}
    }).then(res => {
      let list=res.data
      let equList=[]
      equList.push({ text: '报警设备', value: '' })
      list.forEach(equ => {
        equList.push({text:equ.deviceName,value:equ.deviceId})
      })
      this.setData({equList:equList})
      console.log(this.data.equList)
    })
      this.getInfo()
  },
  // 日期格式化yyyy-mm-dd
  formatDate(date) {
    date = new Date(date);
    let year=date.getFullYear()+"-"
    let month=(date.getMonth()<10?"0"+(date.getMonth() + 1):date.getMonth() + 1)+"-"
    let day=(date.getDate()<10?"0"+date.getDate():date.getDate())
    return year+month+day;
  },
  getInfo(){
    // 获取预警列表
    wx.$req({
      url: '/wms/monitor/getWarnLogListByMonitorId',
      method: 'post',
      data:{beginTime:this.formatDate(new Date())+" 00:00:00",endTime:this.formatDate(new Date())+" 23:59:59",deviceId:this.data.deviceId,status:"0"}
    }).then(res => {
      let alertList=res.data.content
      
      this.setData({ alertList:alertList })
      console.log(this.data.alertList)
    })
  },
  onShow(){
    this.getInfo()
  },
// 跳转详情
  toDetail (e) {
    const info = JSON.stringify(e.currentTarget.dataset.item)
    wx.navigateTo({
      url: '/pages/riskAlarmDetail/index?info='+info
    })
  },

})